package org.company.tool.tools.founder;

import java.io.IOException;
import java.io.OutputStream;
import java.sql.SQLException;

import org.apache.commons.io.IOUtils;
import org.company.tool.bean.Entity;
import org.company.tool.service.EntityTransfer;
import org.company.tool.service.PathTransfer;
import org.company.tool.service.PathTransfer.Path;
import org.company.tool.service.imp.OracleEntityTransfer;
import org.company.tool.tools.Generator;

/**
 * founder的生产工具类
 * @author hucw
 *
 */
public class GeneratorFounder extends Generator {
    private PathTransfer pathTransfer;
    
    public GeneratorFounder(String tableName,String baseDir) throws SQLException {
        this(tableName,"com.founder.barcode","");
    }
    
    public GeneratorFounder(String tableName,String packageName,String baseDir) throws SQLException {
        Entity entity = new Entity(tableName,packageName);
        this.entity = entity;
        EntityTransfer entityTransfer = new OracleEntityTransfer();
        this.entityTransfer = entityTransfer;
        pathTransfer = new PathTransfer(entity,baseDir);
        super.init();
    }
    
    public void generator(Path path) throws IOException {
        OutputStream out = pathTransfer.getOutputStream(path);
        String uri = pathTransfer.getUri(path);
        this.generator(uri, out);
        IOUtils.closeQuietly(out);
    }
    
    /**
     * 生成PO文件
     * @throws IOException
     */
    public void generatorPOJO() throws IOException {
        this.generator(Path.PO);
    }
    
    /**
     * 生成SqlMap文件
     * @throws IOException
     */
    public void generatorSqlMap() throws IOException {
        this.generator(Path.SQLMAP);
    }
    
    /**
     * 生成Action文件
     * @throws IOException
     */
    public void generatorAction() throws IOException {
        this.generator(Path.ACTION);
    }
    
    /**
     * 生成Service文件
     * @throws IOException
     */
    public void generatorService() throws IOException {
        this.generator(Path.ISERVICE);
        this.generator(Path.SERVICEIMPL);
    }
    
    /**
     * 生成DAO文件
     * @throws IOException
     */
    public void generatorDao() throws IOException {
        this.generator(Path.IDAO);
        this.generator(Path.DAOIMPL);
    }
    
    /**
     * 生成JS文件
     * @throws IOException
     */
    public void generatorJS() throws IOException {
        this.generator(Path.JS);
    }
    
    /**
     * 生成JSP文件
     * @throws IOException
     */
    public void generatorJSP() throws IOException {
        this.generator(Path.JSP);
    }
}
